package com.dhkj.web.utils;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * 数据返回统一处理  参考https://www.jianshu.com/p/ff619fea7e22
 */
public abstract class BaseObserverNo<T> implements Observer<T> {
    private static final String TAG = "BaseObserver";

    @Override
    public void onNext(T response) {
        onSuccess(response);
        //在这边对 基础数据 进行统一处理  举个例子：
//        if (response.getCode().trim().equals("0")) {
//            onSuccess(response.getInfo());
//        } else {
//            onFailure(null, response.getMessage());
//        }
    }

    @Override
    public void onError(Throwable e) {//服务器错误信息处理
        onFailure(e, RxExceptionUtil.exceptionHandler(e));
        e.printStackTrace();
    }

    @Override
    public void onComplete() {

    }

    @Override
    public void onSubscribe(Disposable d) {
    }

    public abstract void onSuccess(T result);

    public abstract void onFailure(Throwable e, String errorMsg);

}
